/*
This file compares prior income in the G2G sample between recall measurements
taken before and after COVID-19 for Figure S2.
*/

use "$da/G2G_income_data.dta" , clear

/* Currency conversion, from BDT in year to 2018 USD PPP (most recent year with
PPP conversion rates) to 2019 USD (based on US inflation) */

loc rate_2018 = 30.10843176
loc rate_2019 = 30.67948834
loc rate_2020 = 32.40817971



* Creating common name conventions to allow for cleaner reshape
rename (inc_lastmonth_calc_w1 g2g_ec_q11_w1 g2g_ec_q12_w1) (inc_calc_20 inc_est_20 inc_est_19)

gen inc_remit_20 = inc_lastmonth_remit_w1
gen inc_nonremit_20 = inc_est_20 - inc_remit_20


gen inc_ppp_18 = (hhInc_pres/12) / `rate_2018' 
gen inc_ppp_20 = inc_calc_20 / `rate_2020'
gen inc_ppp_19 = inc_est_19 / `rate_2019'


/*
******************************************************************
* Code to restrict to obs with non-missing income data across the three waves 
******************************************************************
egen non_miss = rownonmiss(inc_ppp_*)
keep if non_miss==3
*/



forvalues i = 18/20 {
	sum inc_ppp_`i', d
	gen inc_ppp_wins_`i' = min(inc_ppp_`i', `r(p99)') if !mi(inc_ppp_`i')
	replace inc_ppp_wins_`i' = `r(p1)' if inc_ppp_wins_`i' < `r(p1)'
}


* CREATE GRAPH

gen byte year = _n+17 if inrange(_n, 1, 3)	

gen int b_earn = .
gen int se_earn = .

forvalues i = 1/3 {
	loc j = `i'+17
	sum inc_ppp_wins_`j'
	replace b_earn = `r(mean)' if _n==`i'
	replace se_earn = `r(sd)'/sqrt(`r(N)') if _n==`i'
}

gen int hi_earn = b_earn + 1.96*se_earn
gen int lo_earn = b_earn - 1.96*se_earn


* Graph style
local pre_color `""240 228 66""'
local cvd_color `""0 114 178""'

graph set window fontface "Helvetica"
twoway (bar b_earn year if year==18, color(`pre_color') barwidth(0.9)) ///
	(bar b_earn year if year>18, color(`cvd_color') barwidth(0.9)) ///
	(rcap hi_earn lo_earn year, lcolor(gs0) msize(small)) ///
	,  plotregion(margin(sides)) ylabel(0(200)600) graphregion(color(white))  ///
	xlabel(18 "April 2018" 19 "April 2019" 20 "April 2020", notick) xtitle("") ///
	ytitle("Avg. Monthly Household Earnings (USD PPP)", axis(1)) ///
	legend(on cols(1) order(1 "Recall Survey Data Collected before COVID Period" 2 "Recall Survey Data Collected during COVID Period"))

graph export "$dfig/recall_BGD.png", replace
